/*
 * -------------------------------------------------------------------------------------------------------*
 * SBS Priceboard V2.0
 * Copyright (C) 2008 Unicom Vietnam JSC
 * -------------------------------------------------------------------------------------------------------* 
 * HeadURL: http://192.168.1.4/svn/priceboard/trunk/SBS_PriceboardV2/front-end/end-user/ipriceboard/
 * LastChangeBy: quanhm
 * LastChangeDate: Aug 7, 2008
 */
package com.unicom.priceboard.util;

import com.unicom.priceboard.data.vo.HaIndex;
import com.unicom.priceboard.thread.HaStockThread;
import com.unicom.priceboard.thread.MarketStatusThread;
import com.unicom.priceboard.thread.TimerThread;

/**
 * <b>description :<b> Class for getting market status of HOSE/HASTC
 * Creation date: Aug 7, 2008
 * @author quan
 */
public class MarketStateUtil {
	
	/**
	 * @return 
	 * 	 1 : being in trading time
	 * 	 0 : Market is closed
	 *	-1 : Pre-Open status
	 */
	
	public static String getHASTC_state() {
		String state = "0"; /*closed is default value*/
		int curTime = TimerThread.CURRENT_TIME;
		int tradingStart = Constants.HASTC_TRADING_START;
		int tradingEnd = Constants.HASTC_TRADING_END;
		String zipPath = DataPath.zipFilePath;
		
		if(curTime>=tradingStart && curTime<=tradingEnd) {
			state = "1";
		}else {
			state = curTime>tradingEnd?"0":(ReadFileUtil.isUpToDate(zipPath)?"-1":"0");
		}
		
		return state;
	}
	
	public static String getHastcState() {
		HaIndex index = HaStockThread.getCurrentIndex();
		if (null != index) {
			return String.valueOf(index.getMarketStatus());
		}
		return "";
	}
	
	public static String getHoseState(){
		return MarketStatusThread.getCurrentMarketState();
	}
}
